<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
<title></title> <jsp:include page="../common/head.jsp"></jsp:include>


<style type="text/css">
body {
	padding-bottom: 40px;
}

.sidebar-nav {
	padding: 9px 0;
}

@media ( max-width : 980px) {
	/* Enable use of floated navbar text */
	.navbar-text.pull-right {
		float: none;
		padding-left: 5px;
		padding-right: 5px;
	}
}
</style>
</head>
<body>
	<div>
		<br />
	</div>
	<div class="definewidth">
		<shiro:hasPermission name="sys:scheduleJob:add"> <a class="btn btn-success"
			href="${path}/scheduleJob/add">添加任务</a> </shiro:hasPermission>
	</div>
	<table class="table table-bordered table-hover definewidth m10">
		<thead>
			<tr>
				<th>任务名</th>
				<th>任务组</th>
				<th>cron表达式</th>
				<th>状态</th>
				<th>描述</th>
				<th>执行任务的类</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${list }"  var="u">
			<tr class="">
				<td>${u.name}</td>
				<td>${u.group}</td>
				<td>${u.cronExpression}</td>
				<td>${u.status}</td>
				<td>${u.description}</td>
				<td>${u.className}</td>
				<td name="${u.name}" group="${u.group}">
				<a href="javascript:void(0)" class="sartJob">启动</a>
				<a href="javascript:void(0)" class="stopJob">暂停</a> 
					<a href="javascript:void(0)" class="startNow">立即触发</a>
					<a href="javascript:void(0)" class="delJob">删除</a></td>
			</tr>
			</c:forEach>
		</tbody>
	</table>
	<jsp:include page="../common/foot.jsp"></jsp:include>
	<script type="text/javascript">
		$(".sartJob").click(function() {
			doJob("${path}/scheduleJob/resume",$(this));
		});
		$(".stopJob").click(function() {
			doJob("${path}/scheduleJob/stopJob",$(this));
		});
		$(".startNow").click(function() {
			doJob("${path}/scheduleJob/startNow",$(this));
		});
		$(".delJob").click(function() {
			doJob("${path}/scheduleJob/delete",$(this));
			setTimeout(function(){
				window.location.reload(true);
			},200);
		});
		function doJob(url,obj){
			var $obj = $(obj);
			var $parent=$obj.parent();
			$.get(url, {
				name : $parent.attr("name"),
				group : $parent.attr("group")
			}, function(data) {
				var data = eval('(' + data + ')');
				if (data.status == '0') {
					alert("操作成功");
				}else{
					alert(data.msg);
				}
			})
		}
	</script>
</body>
</html>
